﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.Routing;
using Htss.Platform.Web;

namespace DreamBox.Web.Box
{
    public class adminBox:ControllerBox
    {

        public object Load()
        {
            string result = string.Empty;
            string t = Request.Form["t"];
            switch (t)
            {
                case "SetStatusForPosts":
                    result= SetStatusForPosts();
                    break;
                case "SetStatusForReply":
                    result= SetStatusForReply();
                    break;
                case "SetStatusForUser":
                    result= SetStatusForUser();
                    break;
                case "SetPropertyForPosts":
                    result= SetPropertyForPosts();
                    break;
            }
            return result;
        }
        DAL.MAction action = new DAL.MAction();
        /// <summary>
        /// 设置主帖属性
        /// </summary>
        /// <returns></returns>
        public string SetPropertyForPosts()
        {
            string result = string.Empty;
            if (Request.Form["PostsID"] != null)
            {
                Model.Posts m = new Model.Posts();
                m.PostsID = int.Parse(Request.Form["PostsID"]);
                m.Property = int.Parse(Request.Form["Property"]);
                if (action.Update(m))
                {
                    result = "操作成功";
                }
            }
            return result;
        }
        /// <summary>
        /// 设置用户状态
        /// </summary>
        /// <returns></returns>
        public string SetStatusForUser()
        {
            string result = string.Empty;
            if (Request.Form["UserID"] != null)
            {
                DAL.User.UserInfo user = new DAL.User.UserInfo();
                if (user.UpdateLockBan(int.Parse(Request.Form["UserID"]),bool.Parse(Request.Form["Status"])?1:0,int.Parse(Session["UserID"].ToString()))>0)
                {
                    result = "操作成功";
                }
            }
            return result;
        }
        /// <summary>
        /// 设置回复状态
        /// </summary>
        /// <returns></returns>
        public string SetStatusForReply()
        {
            string result = string.Empty;
            if (Request.Form["ReplyID"] != null)
            {
                Model.PostsReply m = new Model.PostsReply();
                m.ReplyID = int.Parse(Request.Form["ReplyID"]);
                m.IsStatus = bool.Parse(Request.Form["Status"]);

                if (action.Update(m))
                {
                    result = "操作成功";
                }
            }
            return result;
        }
        /// <summary>
        /// 设置文字状态
        /// </summary>
        /// <returns></returns>
        public string SetStatusForPosts()
        {
            string result = string.Empty;
            if(Request.Form["PostsID"]!=null)
            {
                Model.Posts m = new Model.Posts();
                m.PostsID = int.Parse(Request.Form["PostsID"]);
                m.IsStatus = bool.Parse(Request.Form["Status"]);

                if (action.Update(m))
                {
                    result = "操作成功";
                }
            }
            return result;
        }
    }
}
